<template>
  <div>
    <tableTpl
      :data="ProjectList"
      :columns="columns1"
      v-on:changeItem="changeItem"
      @change="ischage"
    >
      <div slot="table_nav" v-if="current_index >= 3">
        <a-tabs type="card" @change="getData" v-model="paramsData.currin">
          <a-tab-pane key="" tab="全部"> </a-tab-pane>
          <a-tab-pane key="2" tab="录制技术"> </a-tab-pane>
          <a-tab-pane key="3" tab="播出技术"> </a-tab-pane>
        </a-tabs>
      </div>
      <template slot="rightHtml" slot-scope="{ record }">
        <div class="flexBet fontS20" v-if="current_index % 2 != 0">
          <a @click.stop="showPopup('add', record)">提交</a>
          <a @click="goProjectInfo('set', record)">修改</a>
          <a @click.stop="showPopup('del', record)">删除</a>
        </div>
        <div class="flexBet">
          <a
            class="fontS20"
            v-if="record.state == 2"
            @click.stop="showPopup('withdraw', record)"
            >撤回</a
          >
          <!-- <a
            class="flexCon fontS20"
            v-if="current_index % 2 == 0"
            @click.stop="showPopup('look', record)"
            >查看意见</a
          > -->
        </div>
      </template>
    </tableTpl>
    <!-- popup -->
    <popup
      ref="popup"
      title="提示"
      :count="popText"
      @confirm="popConfirm"
    ></popup>
  </div>
</template>

<script>
import popup from "../components/pop/popup.vue";
import tableTpl from "../components/tableTpl/tableTpl.vue";
import {
  getProjectList,
  comitProject,
  urgent,
  ByInstanceId,
  delProject,
  rollBackToBeginFlow,
} from "@/api";
import { mapState } from "vuex";
import { leftDataList } from "@/assets/js/declare";
export default {
  components: {
    popup,
    tableTpl,
  },
  provide() {
    return {
      leftList: leftDataList,
    };
  },
  data() {
    return {
      popText: "", // 弹窗显示内容
      ProjectList: [], // 我的申报列表
      popType: "", // 弹窗类型
      paramsData: leftDataList[0].child[0].dataType, // 接口参数
      current_index: leftDataList[0].child[0].index,
      columns1: [
        // 单位推荐、形式审查、专家评审
        {
          title: "序号",
          dataIndex: "key",
          width: 80,
        },
        {
          title: "申报单位",
          dataIndex: "deptName",
          width: 150,
        },
        {
          title: "作品名称",
          width: 150,
          key: "name",
          slots: { title: "baseName" },
          scopedSlots: { customRender: "name" },
        },
        {
          title: "主要完成人",
          dataIndex: "doneUsers",
          width: 150,
        },
        {
          title: "奖项等级",
          dataIndex: "grade",
          width: 150,
          scopedSlots: { customRender: "grade" },
          // filters: [
          //   {
          //     text: "Joe",
          //     value: "Joe",
          //   },
          //   {
          //     text: "Jim",
          //     value: "Jim",
          //   },
          // ],
          filterMultiple: false,
        },
        // {
        //   title: '申请时间',
        //   dataIndex: 'createTime',
        //   width: 150,
        // },
        {
          title: "审核状态",
          dataIndex: "stateName",
          width: 150,
        },
        {
          title: "操作",
          key: "action",
          scopedSlots: { customRender: "action" },
          width: 190,
          fixed: "right",
        },
      ],
    };
  },
  created() {
    this.getData();
  },
  computed: {
    // ...mapState(["columns"]),
  },
  methods: {
    // 左边框切换
    changeItem(k) {
      this.paramsData = k.dataType;
      // console.log(this.paramsData)
      if (this.paramsData.twoTypeId == 1) {
        this.columns1 = [
          // 单位推荐、形式审查、专家评审
          {
            title: "序号",
            dataIndex: "key",
            width: 80,
          },
          {
            title: "申报单位",
            dataIndex: "deptName",
            width: 150,
          },
          {
            title: "作品名称",
            width: 150,
            key: "name",
            slots: { title: "baseName" },
            scopedSlots: { customRender: "name" },
          },
          {
            title: "主要完成人",
            dataIndex: "doneUsers",
            width: 150,
          },
          {
            title: "类别",
            dataIndex: "kind",
            width: 150,
            scopedSlots: { customRender: "kind" },
            // filters: [
            //   {
            //     text: "Joe",
            //     value: "Joe",
            //   },
            //   {
            //     text: "Jim",
            //     value: "Jim",
            //   },
            // ],
            filterMultiple: false,
          },
          // {
          //   title: "客观图形分（初评）",
          //   dataIndex: "evaluateImage",
          //   width: 150,
          // },
          // {
          //   title: "客观声音分（初评）",
          //   dataIndex: "evaluateVoice",
          //   width: 150,
          // },
          // {
          //   title: "主观分（复评）",
          //   dataIndex: "evaluationF",
          //   width: 150,
          // },
          // {
          //   title: "严重缺陷",
          //   dataIndex: "seriousBug",
          //   width: 150,
          // },
          // {
          //   title: "总分",
          //   dataIndex: "seriousBug",
          //   width: 150,
          // },
          // {
          //   title: "联系人",
          //   dataIndex: "seriousBug",
          //   width: 150,
          // },
          // {
          //   title: "联系电话",
          //   dataIndex: "seriousBug",
          //   width: 150,
          // },
          // {
          //   title: '申请时间',
          //   dataIndex: 'createTime',
          //   width: 150,
          // },
          {
            title: "审核状态",
            dataIndex: "stateName",
            width: 150,
          },
          {
            title: "操作",
            key: "action",
            scopedSlots: { customRender: "action" },
            width: 190,
            fixed: "right",
          },
        ];
      } else if (this.paramsData.twoTypeId == 2) {
        this.columns1 = [
          // 单位推荐、形式审查、专家评审
          {
            title: "序号",
            dataIndex: "key",
            width: 80,
          },
          {
            title: "申报单位",
            dataIndex: "deptName",
            width: 150,
          },
          {
            title: "作品名称",
            width: 150,
            key: "name",
            slots: { title: "baseName" },
            scopedSlots: { customRender: "name" },
          },
          {
            title: "主要完成人",
            dataIndex: "doneUsers",
            width: 150,
          },
          {
            title: "类别",
            dataIndex: "kind",
            width: 150,
            scopedSlots: { customRender: "kind" },
            // filters: [
            //   {
            //     text: "Joe",
            //     value: "Joe",
            //   },
            //   {
            //     text: "Jim",
            //     value: "Jim",
            //   },
            // ],
            // filterMultiple: false,
          },
          // {
          //   title: "录音电平",
          //   dataIndex: "evaluateRecordingLevel",
          //   width: 150,
          // },
          // {
          //   title: "噪声",
          //   dataIndex: "evaluateNoise",
          //   width: 150,
          // },
          // {
          //   title: "失真",
          //   dataIndex: "evaluateDistortion",
          //   width: 150,
          // },
          // {
          //   title: "复接和剪接技术",
          //   dataIndex: "evaluateMultiplex",
          //   width: 150,
          // },
          // {
          //   title: "声道平衡",
          //   dataIndex: "evaluateChannelBalance",
          //   width: 150,
          // },
          // {
          //   title: "相位",
          //   dataIndex: "evaluatePhase",
          //   width: 150,
          // },
          // {
          //   title: "广播电台呼号",
          //   dataIndex: "evaluateBroadcasting",
          //   width: 150,
          // },
          // {
          //   title: "联系人",
          //   dataIndex: "seriousBug",
          //   width: 150,
          // },
          // {
          //   title: "联系电话",
          //   dataIndex: "seriousBug",
          //   width: 150,
          // },
          // {
          //   title: '申请时间',
          //   dataIndex: 'createTime',
          //   width: 150,
          // },
          {
            title: "审核状态",
            dataIndex: "stateName",
            width: 150,
          },
          {
            title: "操作",
            key: "action",
            scopedSlots: { customRender: "action" },
            width: 190,
            fixed: "right",
          },
        ];
      } else {
        this.columns1 = [
          // 单位推荐、形式审查、专家评审
          {
            title: "序号",
            dataIndex: "key",
            width: 80,
          },
          {
            title: "申报单位",
            dataIndex: "deptName",
            width: 150,
          },
          {
            title: "作品名称",
            width: 150,
            key: "name",
            slots: { title: "baseName" },
            scopedSlots: { customRender: "name" },
          },
          {
            title: "主要完成人",
            dataIndex: "doneUsers",
            width: 150,
          },
          {
            title: "奖项等级",
            dataIndex: "grade",
            width: 150,
            scopedSlots: { customRender: "grade" },
            // filters: [
            //   {
            //     text: "Joe",
            //     value: "Joe",
            //   },
            //   {
            //     text: "Jim",
            //     value: "Jim",
            //   },
            // ],
            // filterMultiple: false,
          },
          // {
          //   title: '申请时间',
          //   dataIndex: 'createTime',
          //   width: 150,
          // },
          {
            title: "审核状态",
            dataIndex: "stateName",
            width: 150,
          },
          {
            title: "操作",
            key: "action",
            scopedSlots: { customRender: "action" },
            width: 190,
            fixed: "right",
          },
        ];
      }
      this.current_index = k.index;
      this.getData();
    },
    ischage(e) {
      // console.log(e)
    },
    // 获取页面数据
    async getData() {
      console.log(this.paramsData, "adasdasd");
      var chuandata = this.paramsData;
      if (this.paramsData.currin == "") {
        chuandata.threeTypeId = "";
      } else if (this.paramsData.currin == "2") {
        chuandata.threeTypeId = "1";
      } else if (this.paramsData.currin == "3") {
        chuandata.threeTypeId = "2";
      }
      chuandata.deptlevel = "3";
      // this.paramsData.deptlevel = "";

      // this.paramsData.threeTypeId = this.paramsData.deptlevel;
      const res = await getProjectList(chuandata);
      if (res.code != 200) return;
      res.rows.forEach((i, k) => {
        i.key = k + 1;
      });
      this.ProjectList = res.rows;

      console.log(res);
    },
    // 显示pop弹窗
    showPopup(type, record) {
      this.tableItemData = record;
      this.popType = type;
      switch (type) {
        case "look":
          ByInstanceId(this.tableItemData.baseId, 100).then((res) => {
            this.popText =
              res.data.length > 0
                ? res.data[0].formHistoryDataDTO[1].value
                : "暂无";
          });
          break;
        case "del":
          this.popText = "确定删除本条数据？";
          break;
        case "add":
          this.popText = "提交后不能修改，是否确定提交？";
          break;
        case "hurry":
          this.popText = "是否催办？";
          break;
        case "withdraw":
          this.popText = "是否确认撤回？";
          break;
      }
      this.$refs.popup.showPop();
    },
    // 弹窗确认事件
    popConfirm() {
      switch (this.popType) {
        case "look":
          break;
        case "del":
          delProject(this.tableItemData.baseId).then((res) => {
            if (res.code != 200) return this.$message.error(res.msg);
            this.$notification.success({
              message: "提示",
              description: "删除成功",
            });
            this.getData();
          });
          break;
        case "add":
          // 提交申报项目
          comitProject(this.tableItemData.baseId).then((res) => {
            // console.log(res);
            if (res.code != 200) return this.$message.error(res.msg);
            this.$notification.success({
              message: "提示",
              description: "提交成功",
            });
            this.getData();
          });
          break;
        case "hurry":
          urgent(this.tableItemData.baseId).then((res) => {
            this.$message[res.code != 200 ? "error" : "success"](res.msg);
            if (res.code != 200) return;
          });
          break;
        case "withdraw":
          rollBackToBeginFlow(this.tableItemData.baseId).then((res) => {
            if (res.code != 200)
              return this.$notification.error({
                message: "提示",
                description: res.msg,
              });
            this.$notification.success({
              message: "提示",
              description: res.msg,
            });
            this.getData();
          });
          break;
      }
      this.$refs.popup.hidePop();
    },
    // 预览
    goProjectInfo(type, item) {
      console.log(item);
      let name;
      if (item.oneTypeId == 1) {
        name = "DeclareDetails";
      } else if (item.twoTypeId == 1) {
        name = item.threeTypeId == 1 ? "highVideoReport" : "highVideoBroadcast";
      } else if (item.twoTypeId == 2) {
        name =
          item.threeTypeId == 1 ? "jlhighVideoBroadcast" : "jlhighVideoReport";
      }
      this.$router.push({
        name,
        params: {
          baseId: item.baseId,
          type,
        },
        query: {
          prizeTypeId: item.prizeTypeId,
        },
      });
    },
  },
};
</script>

<style scoped>
.main {
  align-items: flex-start;
}
</style>